package com.cat.binaryTree02;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/binary-search-tree-iterator/?envType=problem-list-v2&envId=xhsq2On3
 * @create 2025/10/2 21:19
 * @since JDK17
 */
class BSTIterator {
    List<Integer> list = new ArrayList<>();
    int n;
    public BSTIterator(TreeNode root) {
        dfs(root);
    }
    void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        list.add(root.val);
        dfs(root.left);
        dfs(root.right);
    }

    public int next() {
        return list.get(n++);
    }

    public boolean hasNext() {
        return n < list.size();
    }
}